package com.gopay.bis.icbc.bcdl.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.common.domain.bank.icbc.bcdl.pay.IcbcMessageData;
import com.gopay.common.domain.bank.icbc.bcdl.pay.IcbcPacketMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.businesses.BcdlService;

public class IcbcBcdlMaskServiceImpl implements BcdlService {
	private final static Logger logger = LoggerFactory.getLogger("BANK_LOG");
	BcdlService queryService;
	BcdlService queryBalService;
//	@Resource(name = "realServicesMap")
	private Map<String,BcdlService> realServices;
	BcdlService queryAcctDetailService;
	@Override
	public Object query(Object obj) throws GopayException {
		return queryService.query(obj);
	}


	@Override
	public Object eft(Object obj) throws GopayException {
		IcbcMessageData sendMsgData=(IcbcMessageData) obj;
		logger.error("find realServices for eft, Label:"+sendMsgData.getLabel());
		BcdlService bcdlService = realServices.get(sendMsgData.getLabel());
		if(null==bcdlService){
			logger.error("can not find bcdlservice for eft, BankOrderId:"+sendMsgData.getBankOrderId());
			throw new RuntimeException("can not find bcdlservice for eft, BankOrderId:"+sendMsgData.getBankOrderId());
		}
		
		return bcdlService.eft(obj);
	}
	
	@Override
    public Object packetEft(Object object) throws GopayException {
        IcbcPacketMessage sendPacketMsg = (IcbcPacketMessage) object;
        logger.error("find realServices for packetEft, Label:" + sendPacketMsg.getLabel());
        BcdlService bcdlService = realServices.get(sendPacketMsg.getLabel());
        if (null == bcdlService) {
            logger.error("can not find bcdlservice for packetEft, packetNo:" + sendPacketMsg.getPacketNo());
            throw new RuntimeException("can not find bcdlservice for packetEft, packetNo:"
                    + sendPacketMsg.getPacketNo());
        }

        return bcdlService.packetEft(object);
    }
	
    @Override
    public Object queryPacket(Object object) throws GopayException {
        IcbcPacketMessage sendPacketMsg = (IcbcPacketMessage) object;
        logger.error("find realServices for queryPacket, Label:" + sendPacketMsg.getLabel());
        BcdlService bcdlService = realServices.get(sendPacketMsg.getLabel());
        if (null == bcdlService) {
            if (null == sendPacketMsg.getIcbcMessageDatas() || sendPacketMsg.getIcbcMessageDatas().size() <= 0) {
                logger.error("can not find bcdlservice for queryPacket, packetNo:" + sendPacketMsg.getPacketNo());
                throw new RuntimeException("can not find bcdlservice for queryPacket, packetNo:"
                        + sendPacketMsg.getPacketNo());
            }
            bcdlService = queryService;
        }

        return bcdlService.queryPacket(object);
    }

	@Override
	public Object queryBalance(Object obj) throws GopayException {
		return queryBalService.queryBalance(obj);
	}

    @Override
    public Object queryAcctDetail(Object object) throws GopayException {
        return queryAcctDetailService.queryAcctDetail(object);
    }
	
	public BcdlService getQueryService() {
		return queryService;
	}


	public void setQueryService(BcdlService queryService) {
		this.queryService = queryService;
	}


	public Map<String, BcdlService> getRealServices() {
		return realServices;
	}


	public void setRealServices(Map<String, BcdlService> realServices) {
		this.realServices = realServices;
	}


	public BcdlService getQueryBalService() {
		return queryBalService;
	}


	public void setQueryBalService(BcdlService queryBalService) {
		this.queryBalService = queryBalService;
	}


    public BcdlService getQueryAcctDetailService() {
        return queryAcctDetailService;
    }


    public void setQueryAcctDetailService(BcdlService queryAcctDetailService) {
        this.queryAcctDetailService = queryAcctDetailService;
    }
	
}	
